package com.gdziarmaga.webshop.book.model;

import java.io.Serializable;

import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.gdziarmaga.webshop.core.dao.GenericDaoImpl;

@Repository("bookRepo")
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public class BookDAOImpl extends GenericDaoImpl<Book, Long> implements BookDAO, Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -723252801149749844L;

	@Override
	public Book findProductByTitle(String title) {
		return getObjectByCriteria(createDetachedCriteria().add(Restrictions.eq(Book.TITLE, title)));
	}

	@Override
	public Book findProductByISBN(String isbn) {
		return getObjectByCriteria(createDetachedCriteria().add(Restrictions.eq(Book.ISBN, isbn)));
	}

	@Override
	public Book findProductByIssue_year(int issue_year) {
		return getObjectByCriteria(createDetachedCriteria().add(Restrictions.eq(Book.ISSUE_YEAR, issue_year)));

	}

	@Override
	public Book findProductByPublisher(String publisher) {
		return getObjectByCriteria(createDetachedCriteria().add(Restrictions.eq(Book.PUBLISHER, publisher)));

	}

	@Override
	public Book findProductBySection(String section) {
		return getObjectByCriteria(createDetachedCriteria().add(Restrictions.eq(Book.SECTION, section)));
	}

	@Override
	public Book findProductByPrice(float price) {
		return getObjectByCriteria(createDetachedCriteria().add(Restrictions.eq(Book.PRICE, price)));

	}
}
